package com.atguigu.paymentdemo.controller;

import com.atguigu.paymentdemo.service.OrderInfoService;
import com.atguigu.paymentdemo.vo.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @projectName: payment-demo
 * @package: com.atguigu.paymentdemo.controller
 * @className: OrderController
 * @author: 躺着认真玩
 * @description: 订单服务
 * @date: 2025/6/8 20:14
 * @version: 1.0
 */
@RestController
@RequestMapping("/api")
@Slf4j
@CrossOrigin //开放前端的跨域访问
public class OrderInfoController {
    @Autowired
    private OrderInfoService orderInfoService;
    @PostMapping("/wx-pay/native/{id}")
    public R wxPay(@PathVariable String id){
        return orderInfoService.creatOrder(id);

    }
    @GetMapping("/order-info/list")
    public R orderList(){
        return orderInfoService.orderList();

    }

    /**
     * 取消订单
     * @param outOrderId
     * @return
     */
    @PostMapping("/wx-pay/cancel/{outOrderId}")
    public R cancleOrder(@PathVariable String outOrderId){
        return  orderInfoService.cancleOrder(outOrderId);
    }

    /**
     * 申请退款
     * @param outOrderId
     * @return
     */
    @PostMapping("/wx-pay/refunds/{outOrderId}/{reson}")
    public R refundOrder(@PathVariable String outOrderId){
        return  orderInfoService.refundOrder(outOrderId);
    }

    /**
     * 下载交易账单
     * @param outOrderId
     * @return
     */
    @GetMapping("/wx-pay/downloadbill/{date}/tradebill")
    public R downloadOrder(@PathVariable String date){
        return  orderInfoService.downloadOrder(date);
    }
}
